//
//  NewsTableViewCell.m
//  ZhongKeXinHeater
//
//  Created by Kendama on 2017/6/2.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "NewsTableViewCell.h"
#import "NewsModel.h"

@interface NewsTableViewCell ()

@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *newsLabel;
@property (nonatomic, strong) UIImageView *typeIV;
@property (nonatomic, strong) UIView *bgView;


@end

@implementation NewsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self masLayoutSubviews];
    }
    return self;
}


- (void)masLayoutSubviews{
    __weak UIView *superView = self;
    self.backgroundColor = [UIColor groupTableViewBackgroundColor];
//    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(superView);
//        make.centerX.equalTo(superView);
//        make.width.mas_equalTo(px1080Width(500));
//        make.height.mas_equalTo(px1920Height(80));
//    }];
    
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(superView);
        make.bottom.equalTo(superView);
        make.left.equalTo(superView).with.offset(px1080Width(50));
        make.right.equalTo(superView).with.offset(-px1080Width(50));
    }];
    
//    [self.typeIV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.bgView);
//        make.left.equalTo(self.bgView).with.offset(px1080Width(53));
//        make.width.height.mas_equalTo(px1920Height(145));
//    }];
    
    [self.newsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.bgView);
//        make.left.equalTo(self.typeIV.mas_right).with.offset(px1080Width(66));
        make.top.equalTo(self.bgView).with.offset(px1080Width(20));
        make.bottom.equalTo(self.bgView).with.offset(-px1080Width(20));
        make.left.equalTo(self.bgView).with.offset(px1080Width(20));
        make.right.equalTo(self.bgView).with.offset(-px1080Width(20));


    }];
}


- (void)setDict:(NSDictionary *)dict {
    
}

- (void)setNewsModel:(NewsModel *)newsModel {
    self.newsLabel.text = newsModel.content;
    self.timeLabel.text = [NSString getTimeWithTimestamp:newsModel.ctime format:@"yyyy-MM-dd HH:mm"];
}


- (UILabel *)newsLabel
{
    if(!_newsLabel)
    {
        __weak UIView *superView = self.bgView;
        _newsLabel = [[UILabel alloc]init];
        [superView addSubview:_newsLabel];
        _newsLabel.numberOfLines = 0;
        [_newsLabel setFont:[UIFont systemFontOfSize:px1080Width(42)]];
        [_newsLabel setTextColor:[UIColor colorWithHexString:@"#231916"]];
//        _newsLabel.text = @"【一杯子】大降价，赶紧进来抢购吧！";
    }
    return _newsLabel;
}
- (UIImageView *)typeIV
{
    if(!_typeIV)
    {
        __weak UIView *superView = self.bgView;
        _typeIV = [[UIImageView alloc]init];
        [superView addSubview:_typeIV];
        _typeIV.image = [UIImage imageNamed:@"icon_warning"];
    }
    return _typeIV;
}


- (UIView *)bgView
{
    if(!_bgView)
    {
        __weak UIView *superView = self.contentView;
        _bgView = [[UIView alloc]init];
        _bgView.layer.borderColor = [[UIColor lightGrayColor]CGColor];
        _bgView.layer.cornerRadius = 5;
        _bgView.layer.borderWidth = 0.5;
        [_bgView.layer setMasksToBounds:YES];
        _bgView.backgroundColor = [UIColor whiteColor];
//        _bgView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
        [superView addSubview:_bgView];
    }
    return _bgView;
}

- (UILabel *)timeLabel
{
    if(!_timeLabel)
    {
        UIView *superView = self.contentView;
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = [UIFont systemFontOfSize:px1920Height(36)];
        _timeLabel.textColor = [UIColor colorWithHexString:@"#9B9B9B"];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
//        _timeLabel.text = @"2017-06-20 18:00";
        _timeLabel.backgroundColor = [UIColor colorWithRed:227/255.0 green:227/255.0 blue:229/255.0 alpha:1];
        _timeLabel.layer.cornerRadius = px1920Height(40);
        _timeLabel.clipsToBounds = YES;
        [superView addSubview:_timeLabel];

    }
    return _timeLabel;
}



+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"NewsTableViewCell";
    id cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
